Passed
Push — master ( fd5993...4f9324 )
by Vinicius
03:57 queued 01:54
created

page-title.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 1
ccs 1
cts 1
cp 1
crap 1
rs 9.85
1 2
import { buildPageTitle, safeString, isFunction } from './utils'
2
3
/**
4
 * if use ssr document is not available
5
 * @method isBrowser
6
 * @return {Boolean}
7
 */
8 10
const isBrowser = () => (typeof document !== 'undefined')
9
10
/**
11
 * update document.title
12
 * @method setPageTitle
13
 * @param  {String}     value new title
14
 * @param  {Object}     options buildPageTitle options
15
 * @return {void}
16
 */
17 2
const setPageTitle = (value, options) => {
18
  // test if not is a browser
19
  /* istanbul ignore next: SSR */
20
  if (!isBrowser()) {
21
    console.warn('no browser enviroment')
22
    return
23
  }
24
25
  // test if title is empty
26 10
  if (safeString(value).length > 0) {
27 8
    const { setTitleMethod } = options
28 8
    const title = buildPageTitle(value, options)
29
30
    // use custom setTitle method
31 8
    if (setTitleMethod && isFunction(setTitleMethod)) {
32
      setTitleMethod(title)
33
      return
34
    }
35
36 8
    document.title = title
37
  }
38
}
39
40
export { setPageTitle }
41